from langchain_community.vectorstores.qdrant import Qdrant
from langchain_core.embeddings import Embeddings
from qdrant_client import qdrant_client
from qdrant_client.http.models import VectorParams, Distance

import config

client = qdrant_client.QdrantClient(
    path=config.db_path, prefer_grpc=True
)


def create_collection(collection_name: str):
    if client.collection_exists(collection_name):
        return False
    else:
        return client.create_collection(collection_name, vectors_config=VectorParams(size=1536,distance=Distance.COSINE))


def delete_collection(collection_name: str):
    return client.delete_collection(collection_name)


def get_collections():
    collections = []
    collection_response = client.get_collections()
    for collection_info in collection_response.collections:
        collections.append(collection_info.name)
    return collections


def get_collection_db(collection_name: str, embedding: Embeddings):
    return Qdrant(
        client=client, collection_name=collection_name,
        embeddings=embedding
    )
